package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter@Setter
public class TravelCommend extends BaseDomain{
    public static final Integer TYPE_MONTH = 2;
    public static final Integer TYPE_WEEK = 1;
    public static final Integer TYPE_STRATEGY = 3;
    //游记
    private Travel travel;
    //推荐标题
    private String title;
    //副标题
    private String subTitle;
    //推荐封面
    private String coverUrl;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date schedule;
    //推荐类型
    private Integer type;
    //获取推荐类型名
    public String getTypeName(){
        String msg = "每周推荐";
        if(TYPE_STRATEGY == type){
            msg = "攻略推荐";
        }else if(TYPE_MONTH == type){
            msg = "每月推荐";
        }
        return msg;
    }
    public String getJson(){
        Map<String, Object> map = new HashMap<>();
        map.put("title",title);
        map.put("type",type);
        map.put("schedule", DateUtil.formatDate(schedule));
        map.put("coverUrl",coverUrl);
        map.put("subTitle",subTitle);
        map.put("id",id);
        if(travel!=null){
            map.put("travelId",travel.id);
        }
        return JSONUtil.toJSONString(map);
    }
}